<?php
/**
 * Created by PhpStorm
 * User: rain
 * Date: 2018/12/26
 * Time: 下午5:23
 */

namespace App\Models;

use App\Utils\FileUtil;
use Illuminate\Database\Eloquent\Model;


/**
 * Class Classify
 * @property integer $id
 * @property string $name
 * @property integer $sort
 * @property integer $is_show
 * @property integer $book_ct
 * @property string $icon
 * @property string $description
 * @property string $created_at
 * @property string $updated_at
 * @package App\Models
 */
class Classify extends Model
{
    protected $table = 'classify';

    protected $guarded=['id'];

    const SHOW_NO   = 0;
    const SHOW_YES = 1;
    public static $isShowLabels = [
        self::SHOW_NO => '不显示',
        self::SHOW_YES => '显示',
    ];

    public function getIconAttribute($value)
    {
        return FileUtil::getDomain($value);
    }

    public function books()
    {
        return $this->belongsToMany(Book::class, 'classify_book', 'classify_id', 'book_id');
    }
}
